<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="assets/js/jquery-1.8.3.min.js"></script>
<script type="text/javascript">

	function disPage(obj){
		var i = $(obj).attr("i");
		//声明iframe
		var iframe = $("<iframe></iframe>");
		//设置iframe的宽和高
		iframe.css("width","100%");
		iframe.css("height","100%");
		if(i == 0){
			//添加销售
			iframe.attr("src","sale_add.html");
		}else if(i == 1){
			//查询销售
			iframe.attr("src","sale_list.html");
		}else if(i == 2){
			//查询库存
			iframe.attr("src","product_quantity.html");
		}
		//选中div,向iframe扔进去
		$("#page").html(iframe);
	}
	
	//退出登录
	function logout(){
		$.ajax({
			url : "http://localhost/user/logout",
			data : null,
			type : "POST",
			xhrFields:{withCredentials:true},
            dataType : "json",
			success : function(msg){
				if(msg.code == 0){
					//退出登录成功
					location.href="index.html"
				}else{
					alert(msg.msg);
				}
			},
			error : function(msg){
				alert("服务器正在更新,请稍后再试....");
			}
		});
	}

	$(function(){
		$.ajax({
			url : "http://localhost/user/info",
			data : null,
			type : "get",
			dataType : "json",
			xhrFields: { 
				withCredentials: true//允许带上凭据
			},
			success : function(msg){
				if(msg.code == 0){
				    $("#userInfo").html('欢迎您&nbsp;'+msg.data+'&nbsp;&nbsp;<a href="javascript:;" onclick="logout()">退出登录</a>');
				}else{
                    $("#userInfo").html('<a href="index.html">请您登录</a>');
                }
			},
			error : function(msg){
                $("#userInfo").html('<a href="index.html">请您登录</a>');
			}
		});
	});
	
</script>
</head>
<body>
	<h3><span id="userInfo"><a href="index.html">请您登录</a></span></h3>
	<br />
	<br />
	<a href="javascript:;" onclick="disPage(this)" i="0">销售</a>
	<br />
	<br />
	<a href="javascript:;" onclick="disPage(this)" i="1">查看销售记录</a>
	<br />
	<br />
	<a href="javascript:;" onclick="disPage(this)" i="2">查看库存</a>
	
	<div id="page" style="line-height:333px;text-align:center;border:2px solid blue;width:650px;height:400px;position: absolute;left: 140px;top:90px;">
		<h1>欢迎使用超级无敌进销存</h1>
	</div>
</body>
</html>


